/**
 * @author luguoxiang
 * @date 2021-09-07
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { request, createApi } from '@/soar';
import { HttpConfig } from '@/soar/utils/api/request';

export const basePath = '/system/sys-config';

/**
 * 更新配置
 * @param code
 * @param value
 */
function set(code: string, value: any): Promise<any> {
  return request.post(`${basePath}/set/${code}`, {
    title: '更新配置',
    data: value,
    headers: { 'Content-Type': 'application/json' },
  });
}

/**
 * 获取配置
 * @param code
 */
function get(code: string, cfg?: HttpConfig): Promise<any> {
  return request
    .get(`${basePath}/${code}`, { title: '获取配置', errorMsg: false, ...cfg })
    .then((res) => JSON.parse(res || '{}'));
}

export default {
  ...createApi(basePath, '系统配置'),
  set,
  get,
  clearCache: () => request.post(`${basePath}/clear-cache`),
};
